
export async function parseFieldInfo(relativePath: string, typeName: string): Promise<Map<string, string>> {
  const fieldMap = new Map<string, string>()

  try {
    const response = await fetch(relativePath)
    console.log("response",response);
    const data = await response.text()
    console.log("data",data,"!!");

    // 匹配目标类型定义
    const interfaceRegex = new RegExp(`export\\s+(interface|type)\\s+${typeName}\\s*{([\\s\\S]*?)}`)
    const match = data.match(interfaceRegex)

    if (!match) {
      throw new Error(`未找到 ${typeName} 类型定义`)
    }

    const interfaceBody = match[2]

    // 匹配字段名和类型
    const fieldRegex = /\s*(\w+)\??:\s*([\w\d<>, |{}]+);?/g
    let fieldMatch: RegExpExecArray | null
    while ((fieldMatch = fieldRegex.exec(interfaceBody)) !== null) {
      const fieldName = fieldMatch[1]
      const fieldType = fieldMatch[2].trim()
      fieldMap.set(fieldName, fieldType)
    }

    return fieldMap
  } catch (err) {
    console.error('读取文件时出错:', err)
    return fieldMap
  }
}
